package com.info.zhiduoduo.core.dto.pingan;

import com.info.zhiduoduo.common.constants.Constants;
import com.info.zhiduoduo.repository.entity.crowdsource.CrowdsourceTradeRecordItem;
import com.info.zhiduoduo.repository.entity.order.TradeRecord;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * 平安银行企业单笔资金划转
 *
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class PinganTransferFormBean {
	private int paymentMerchant;
	/**
	 * 业务参考号
	 */
	private String tradeNo;
	/**
	 * 转账凭证号
	 */
	private String thirdVoucher;
	/**
	 * 金额
	 */
	private BigDecimal amount;
	/**
	 * 银行卡号
	 */
	private String acctno;
	/**
	 * 户名
	 */
	private String acctname;
	/**
	 * 跨行标记
	 */
	private String unionFlag;
	/**
	 * 交易描述
	 */
	private String describe;

	public static PinganTransferFormBean of(CrowdsourceTradeRecordItem recordItem, Integer merchantId, Integer workType) {
		return new PinganTransferFormBean()
				.setPaymentMerchant(merchantId)
				.setAcctname(recordItem.getAcctname())
				.setAcctno(recordItem.getAcctno())
				.setAmount(recordItem.getTradeamount().setScale(2, RoundingMode.DOWN))
				.setTradeNo(recordItem.getTradeNo())
				.setThirdVoucher(recordItem.getTradeNo())
				.setUnionFlag(recordItem.getBankname().contains("平安银行") ? Constants.UNION_FLAG_IN : Constants.UNION_FLAG_OUT)
				.setDescribe(Constants.WORK_TYPE_1 == workType ? "服务费" : "服务费");
	}
	public static PinganTransferFormBean of(TradeRecord tradeRecord) {
		return new PinganTransferFormBean()
				.setPaymentMerchant(tradeRecord.getMerchantid())
				.setAcctname(tradeRecord.getAcctname())
				.setAcctno(tradeRecord.getAcctno())
				.setAmount(tradeRecord.getTradeamount().setScale(2, RoundingMode.DOWN))
				.setTradeNo(tradeRecord.getTradeno())
				.setUnionFlag(tradeRecord.getBankname().contains("平安银行") ? Constants.UNION_FLAG_IN : Constants.UNION_FLAG_OUT)
				.setThirdVoucher(tradeRecord.getTradeno())
				.setDescribe(" 支付");
	}
}
